package com.xiangha.springboot.controller;

import com.xiangha.springboot.pojo.Users;
import com.xiangha.springboot.service.impl.PointsServiceImpl;
import com.xiangha.springboot.service.impl.UsersServiceImpl;
import com.xiangha.springboot.utils.JwtUtils;
import com.xiangha.springboot.utils.ResponseMsg;
import io.jsonwebtoken.Claims;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 积分表 前端控制器
 * </p>
 *
 * @author itlong
 * @since 2025-09-19 03:40:35
 */
@RestController
public class PointsController {
    @Autowired
    PointsServiceImpl pointsService;
    @Autowired
    UsersServiceImpl usersService;
    @RequestMapping("/user/points")
    public Users getPoints(HttpServletRequest request) {
        String token=request.getHeader("token");
        Claims claims= JwtUtils.parseJWT(token);
        System.out.println("当前登录的用户信息:"+claims.getSubject());
        return usersService.getById(claims.getId());
    }
    @RequestMapping("/points/change-records")
    public ResponseMsg getChangeRecords(HttpServletRequest request) {
        String token=request.getHeader("token");
        Claims claims= JwtUtils.parseJWT(token);
        return ResponseMsg.getInstance(200,pointsService.getPoints(claims.getId()));
    }

}
